package com.heima.kafka.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈辉
 * @data 2024 10:13
 */
@RestController
@Slf4j
public class KafkaProducer {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/send")
    public void sendMsg(){
        kafkaTemplate.send("topic-itheima","key-1","hello,kafka!");
        log.info("发出消息：key-1,hello,kafka!");
    }
}
